/**
 * Created with IntelliJ IDEA.
 * User: Lorenzo
 * Date: 15-6-2
 * Time: 下午8:19
 * To change this template use File | Settings | File Templates.
 */

var getPurchaseGroup = function(id) {

    $.get("/cm/purchaseGroup/view/" + id, function(data) {
        renderPurchaseGroup(data);
    })

    $.ajax({
        url:"",
        dataType:"json",
        success: function(data) {
            this.purchaseGroupModel.fetchModel(data);
        }
    })

}
var renderPurchaseGroup = function(purchaseGroup) {
    $('#purchaseCode').html(purchaseGroup.purchateam_code);
    $('#purchase_name').html(purchaseGroup.purchateam_name);
    $('#CreateUser').html(purchaseGroup.CreateUser);
    $('#purchase_per').html(purchaseGroup.purchase_per);
    $('#CreateDate').html(purchaseGroup.CreateDate);
    var purchasePersons = eval('('+purchaseGroup.purchase_persos+')');
    var purchaseProduct = eval('('+purchaseGroup.purchase_products+')');
    if(purchasePersons != null && purchasePersons.length>0) {
        renderPurchasePerson(purchasePersons);
    }
    if(purchaseProduct !=null && purchaseProduct.length>0) {
        renderPurchaseProduct(purchaseProduct);
    }
}

var renderPurchasePerson = function(purchasePersonList) {
    if(purchasePersonList != null && purchasePersonList.length>0) {
        var trHtml="";
        $(purchasePersonList).each(function(i, val) {
            trHtml += "<tr><td>"+(i+1)+"</td><td>"+val.purchaser_code+"</td><td>"+val.purchaser_name+"</td><td>"+val.purchaser_phone+"</td></tr>"
        })
        $('#metaria >table').append(trHtml);
    }
}

var renderPurchaseProduct = function(purchaseProductList) {
    if(purchaseProductList != null && purchaseProductList.length>0) {
        var trHtml="";
        $(purchaseProductList).each(function(i, val) {
            trHtml +="<tr><td>"+(i+1)+"</td><td>"+val.pro_code +"</td><td>"+val.pro_name+"</td><td>"+val.pro_norms+"</td><td>"+val.pro_brand+"</td></tr>"
        })
        $('#purchaseStaff > table').append(trHtml);
    }
}
